package com.zpkj.portal.utils;

/**
 * Created by ChenK on 2017/7/18.
 */
public class StringQueryUtils {
//    public static void main(String[] args) {
//        System.out.println(getStringNum("s707fe"));
//    }

    //获取字符串中的阿拉伯数字，如"您收入1000元"，返回"1000"
    public static String getStringNum(String str) {
        int len = str.length();
        String temp = "";
        if (len == 0) {
            return temp;
        }
        for (int i = 0; i < len; i++) {
            int ascii = (int) str.charAt(i);
            if (ascii > 47 && ascii < 58) {
                temp += str.charAt(i);
            }
        }
        return temp;
    }

    /**
     * 判断前num位是否为数字
     * @param str 字符
     * @param num 需要判断的位数
     * @return 是否都为数字
     */
    public static boolean isNum(String str, int num) {
        int length = str.length() > num ? num : str.length();
        boolean flag = false;
        for (int i = 0; i < length; i++) {
            int ascii = (int) str.charAt(i);
            if (ascii > 47 && ascii < 58) {
                flag = true;
            } else {
                return false;
            }
        }
        return flag;
    }

}
